package com.qingcloud.task.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingcloud.task.mapper.TaskSourceMapper;
import com.qingcloud.task.model.TaskSource;
import com.qingcloud.task.service.TaskSourceService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 任务关联来源数据id 服务实现类
 * </p>
 *
 * @author zhengjibin
 * @since 2022-01-24
 */
@Service
public class TaskSourceServiceImpl extends ServiceImpl<TaskSourceMapper, TaskSource> implements TaskSourceService {

    @Override
    public void saveSource(List<Long> sourceIds, Integer dataType, Long taskId) {
        if (CollectionUtils.isEmpty(sourceIds)){
            return;
        }
        List<TaskSource> sourceList = new ArrayList<>();
        sourceIds.forEach(e -> {
            TaskSource source = new TaskSource();
            source.setDataType(dataType);
            source.setTaskId(taskId);
            source.setSourceId(e);
            sourceList.add(source);
        });
        saveBatch(sourceList);
    }
}
